require 'logger'

$logger =
  begin
#    # us the rails logger if running under rails
#    RAILS_DEFAULT_LOGGER
#  rescue NameError
    unless ENV['INFOLR_LOG'].nil?
      # write to environment variable $INFOLR_LOG if set
      Logger.new(ENV['INFOLR_LOG'], 1, 100*1024) 
    else
      Logger.new(STDOUT, 1, 100*1024); 
    end
  end


  class Logger
    def format_message(severity, timestamp, progname, msg)
      "#{timestamp.strftime('%H:%M')} #{severity}: #{msg}\n" 
    end
  end
# if user has specified loglevel we use that, otherwise we use default level
# in the environment variable INFOLR_LOG_LEVEL we expect numbers, which we 
# have to convert
if ENV['INFOLR_LOG_LEVEL'].nil?
  $logger.level = Logger::DEBUG
else
  $logger.level = ENV['INFOLR_LOG_LEVEL'].to_i
end
